<template>
  <div class="tab-control">
    <div
      class="tab-control-item"
      v-for="(item, index) in titles"
      :key="index"
      @click="itemClick(index)"
    >
      <span>{{ item }}</span>
    </div>
  </div>
</template>
<script>
import { ref } from "vue";
export default {
  props: {
    titles: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  setup(props, { emit }) {
    let currentIndex = ref();
    const itemClick = (index) => {
      currentIndex.value = index;
      emit("tabClick", index);
    };
    return {
      currentIndex,
      itemClick,
    };
  },
};
</script>
<style lang="less" scoped>
.tab-control {
  display: flex;
  height: 40px;
  text-align: center;
  font-size: 14px;
  background-color: #fff;
  width: 100%;
  position: sticky;
  top: 44px;
  z-index: 999;
  .tab-control-item {
    flex: 1;
    span {
      line-height: 40px;
      &:hover {
        color: #42b983;
        border-bottom: 3px solid #42b983;
      }
    }
  }
}
</style>